package view.controller;

import common.NowUser;
import common.User;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import view.ChangeInfo;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class PersonalController implements Initializable {
    public Label id;
    public Label gender;
    public Label name;
    public Label email;
    public Label birth;
    public Label address;
    public Label sign;
    public Label changebt;
    public ImageView photo;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        User user=new User();
        user= NowUser.getUser();
        if(user.getName()!=null && !user.getName().equals("")){
            name.setText(user.getName());
        }
        if(user.getId()!=null && !user.getId().equals("")){
            id.setText(user.getId());
        }
        if(user.getEmail()!=null && !user.getEmail().equals("")){
            email.setText(user.getEmail());
        }
        if(user.getBirth()!=null && !user.getBirth().equals("") && !user.getBirth().equals("null")){
            birth.setText(user.getBirth());
        }
        if(user.getGender()!=null && !user.getGender().equals("") && !user.getGender().equals("null")){
            gender.setText(user.getGender());
        }
        if(user.getAddress()!=null && !user.getAddress().equals("") && !user.getAddress().equals("null")){
            address.setText(user.getAddress());
        }
        if(user.getSign()!=null && !user.getSign().equals("")){
            sign.setText(user.getSign());
        }
        if(user.getHeadimage()!=null && !user.getHeadimage().equals("")&&!user.getHeadimage().equals("null")){
            // System.out.println(user.getPhoto());
            Image image=new Image("file:" + user.getHeadimage());
            photo.setImage(image);
        }else{
            Image image=new Image("view/photo/默认头像.jpg");
            photo.setImage(image);
        }
    }

    public void tochange() throws IOException {
        Stage stage = (Stage) changebt.getScene().getWindow();
        ChangeInfo rj=new ChangeInfo();
        rj.start(stage);
    }
}
